
//生成检验报告数据
import tiyData from "./paymentAndSafe_data";

export const initCheckData = (self, tiyData, userId, orderId) => {
  self.$Spin.show();
  let param = {
    "userId":userId,
    "orderId":orderId,
  };
  self.$apiNewOrder.getCheckDataList(param).then(function (response) {
    if(response.success){
      self.$Message.success("生成订单检查报告");
      self.reloadList();
    }else{
      self.$Message.error(response.errorMessage);
    }
    self.$Spin.hide();
  });
};

/**
 * 确认订单收款
 * @param self
 * @param tiyData
 */
export const confirmOrderPay = (self, tiyData,index) => {
  if(tiyData.tStatus.modalVerify.money==''){
    self.$Message.error("请确认款项是否到账");
    return;
  }
  if(tiyData.tStatus.modalVerify.repeat==''){
    self.$Message.error("请确认信息是否重复");
    return;
  }
  self.$Spin.show();
  let orders = [];
  if(index>=0){
    let order = {};
    order.id = tiyData.tData.orderList[index].id;
    order.serialNumber = tiyData.tData.orderList[index].serialNumber;
    orders.push(order);
  }else{
    orders = createOrders(self.messageSelected,tiyData);
  }
  let data = {
    "orders" : orders,
    "auditInfo":{
      money:tiyData.tStatus.modalVerify.money,
      repeat:tiyData.tStatus.modalVerify.repeat,
      auditNote:tiyData.tStatus.modalVerify.auditNote,
    },
    "isConfirm" : tiyData.tParams.isConfirmed==1?true:false,
  }
  self.$apiNewOrder.confirmOrders(data).then(function (response) {
    self.$Spin.hide();
    if (response.success) {
      self.$Message.success('确认订单成功!');
      self.messageSelected.splice(0,self.messageSelected.length);
      tiyData.tStatus.modalVerify.isShow = false;
      self.reloadList();
    } else {
      self.$Message.error(response.errorMessage);
    }
  });
};



/**
 * 选中的订单构造传回后台的订单列表
 * @param selectedOrders
 */
function createOrders(selectedOrders,tiyData) {
  let orders = [];
  selectedOrders.forEach(function (item) {
    let order = {};
    order.id = tiyData.tData.orderList[item].id;
    order.serialNumber = tiyData.tData.orderList[item].serialNumber;
    orders.push(order);
  });
  return orders;
}
